package com.example.myandroidapp.kotlin

/*
* mapOf:不可变键值对集合
* mutableMapOf：可变键值对集合
*
* map集合使用方式：通过 map[key] 访问及修改
* mapof(key to value,key2 to value2)
*/
fun main() {
    val map = mapOf(
        1 to "one",
        2 to "two",
        3 to "three"
    )
    //查 [key]
    println("map[1] = " + map[1])
    println(map[4])
    //不能改
//    map[2] = "two"
    map.forEach { t, u -> println("$t:$u") }


    val mutableMap = mutableMapOf(
        1 to "one",
        2 to "two",
        3 to "three"
    )
    //可改值
    mutableMap[2] = "two2"
    println(mutableMap[2])
    //增加也是 [key] 赋值
    mutableMap[4] = "four"
    //删除
    mutableMap.remove(1)
    mutableMap.forEach { t, u -> println("$t:$u") }
}